<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>15.&nbsp;HTTP支持</title>
<link rel="stylesheet" href="css/manual.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html"
	title="Spring Integration Reference Manual">
<link rel="up" href="spring-integration-adapters.html"
	title="Part&nbsp;IV.&nbsp;Integration Adapters">
<link rel="prev" href="gemfire.html" title="14.&nbsp;GemFire Support">
<link rel="next" href="ip.html" title="16.&nbsp;TCP and UDP Support">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084"
	alink="#0000FF">
	<div class="navheader">
		<table width="100%" summary="Navigation header">
			<tr>
				<th colspan="3" align="center">15.&nbsp;HTTP支持</th>
			</tr>
			<tr>
				<td width="20%" align="left"><a accesskey="p"
					href="gemfire.html">上一页</a>&nbsp;</td>
				<th width="60%" align="center">第四部分：集成适配器</th>
				<td width="20%" align="right">&nbsp;<a accesskey="n"
					href="ip.html">下一页</a></td>
			</tr>
		</table>
		<hr>
	</div>
	<div class="chapter" title="15.&nbsp;HTTP支持">
		<div class="titlepage">
			<div>
				<div>
					<h2 class="title">
						<a name="http"></a>15.&nbsp;HTTP支持
					</h2>
				</div>
			</div>
		</div>


		<div class="section" title="15.1&nbsp;简单介绍">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-intro"></a>15.1&nbsp;简单介绍
						</h2>
					</div>
				</div>
			</div>

			<p>
				本章介绍用于发送HTTP请求和处理HTTP输入请求的HTTP支持。HTTP处理都是同步的，即使所有的处理返回代码都是200，因此HTTP支持包括两种网关实现：<code class="classname">HttpInboundEndpoint</code>
				和
				<code class="classname">HttpRequestExecutingMessageHandler</code>
				.
			</p>
		</div>

		<div class="section" title="15.2&nbsp;Http Inbound Gateway">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-inbound"></a>15.2&nbsp;Http输入网关
						</h2>
					</div>
				</div>
			</div>

			<p>
				HTTP要通过HTTP读取消息，你需要使用<em>HTTP输入通道适配器</em>或 <span
					class="emphasis"><em>网关</em></span>。<span
					class="emphasis"><em>HTTP输入适配器</em></span>需要和servlet容器，如<a class="ulink"
					href="http://tomcat.apache.org/" target="_top">Apache Tomcat</a> 或
				<a class="ulink" href="http://www.eclipse.org/jetty/" target="_top">Jetty</a>。其中最简单的方法是使用Spring提供的
				<code class="classname">
					<a class="ulink"
						href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/web/context/support/HttpRequestHandlerServlet.html"
						target="_top">HttpRequestHandlerServlet</a>
				</code>，并在 <span
					class="emphasis"><em>web.xml</em></span> 文件中提供下面的servlet定义：
			</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;servlet&gt;</span>
    <span class="hl-tag">&lt;servlet-name&gt;</span>inboundGateway<span
					class="hl-tag">&lt;/servlet-name&gt;</span>
    <span class="hl-tag">&lt;servlet-class&gt;</span>o.s.web.context.support.HttpRequestHandlerServlet<span
					class="hl-tag">&lt;/servlet-class&gt;</span>
<span class="hl-tag">&lt;/servlet&gt;</span>
			</pre>
			<p>
				注意使servlet名称与bean的名称一致。关于<code class="classname">HttpRequestHandlerServlet</code>
				更详细的信息，请查看《Spring框架参考》中的"<a class="ulink"
					href="http://static.springsource.org/spring/docs/current/spring-framework-reference/html/remoting.html"
					target="_top">Remoting and web services using Spring</a>"。
			</p>
			<p>
				如果把<span class="emphasis"><em>HTTP输入适配器</em></span>
				放入到Spring MVC应用中运行，那么前面提到的显式servlet定义就没有必要了。这种情况下，bean名称和你的网关可以和URL路径匹配，这和Spring MVC控制器bean是相似的做法。更详细的信息，请查看《Spring框架参考》中的"<a class="ulink"
					href="http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html"
					target="_top">Web MVC framework</a>"。
			</p>
			<div class="tip" title="Tip"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Tip">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Tip]" src="images/admon/tip.png"></td>
						<th align="left">小窍门</th>
					</tr>
					<tr>
						<td align="left" valign="top">在<a class="ulink"
							href="https://github.com/SpringSource/spring-integration-samples"
							target="_top">Spring Integration Samples</a>中你可以找到样例程序和相应的配置文件。当中的<a class="ulink"
							href="https://github.com/SpringSource/spring-integration-samples/tree/master/basic/http"
							target="_top">Http Sample</a> 应用演示了如何实现Spring
							Integration的HTTP支持。
						</td>
					</tr>
				</table>
			</div>
			<p>HTTP输入终结点的一个简单例子如下：</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"httpInbound"</span>
  <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway"</span><span
					class="hl-tag">&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"requestChannel"</span> <span class="hl-attribute">ref</span>=<span
					class="hl-value">"httpRequestChannel"</span><span class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"replyChannel"</span> <span class="hl-attribute">ref</span>=<span
					class="hl-value">"httpReplyChannel"</span><span class="hl-tag"> /&gt;</span>
<span class="hl-tag">&lt;/bean&gt;</span>
			</pre>
			<p>
				The
				<code class="classname">HttpRequestHandlingMessagingGateway</code>
				accepts a list of
				<code class="interfacename">HttpMessageConverter</code>
				instances or else relies on a default list. 转换器允许定制从<code class="interfacename">HttpServletRequest</code>
				到
				<code class="interfacename">Message</code>的转换映射。缺省的转换器封装了简单的策略，比如说把String消息转换成一个内容类型为“text”的<span class="emphasis"><em>POST</em></span>
				请求。详细说明请查看Javadoc。
			</p>
			<p>
				从本次发布的版本开始，MultiPart文件将受到支持。如果一个请求被包装成<span class="emphasis"><em>MultipartHttpServletRequest</em></span>，同时采用缺省的转换器，该请求转成的消息的内容将会是MultiValueMap。这个MultiValueMap对象可能包含下面各种类型的值：字节数组，字符串，或者是Spring的<code class="interfacename">MultipartFile</code>。具体是何值将跟据不同部分的内容类型。
			</p>
			<div class="note" title="Note"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Note">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Note]" src="images/admon/note.png"></td>
						<th align="left">注意</th>
					</tr>
					<tr>
						<td align="left" valign="top">和Spring DispatcherServlet一样，HTTP输入终结点会在上下文中尝试找到类型为MultipartResolver，名称为
						“multipartResolver”的bean。找到这个bean，Spring Integration才会支持MultipartFile。否则，MultipartFile
						将不会被支持，这时如果尝试把multipart-file请求转换成Spring Integration消息，转换处理会失败。关于Spring中如何支持MultipartResolver，更详细的信息请参考
						 <a
							class="ulink"
							href="http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-multipart"
							target="_top">《Spring Reference Manual》</a>.
						</td>
					</tr>
				</table>
			</div>
			<p></p>
			<p>
				In sending a response to the client there are a number of ways to
				customize the behavior of the gateway. By default the gateway will
				simply acknowledge that the request was received by sending a 200
				status code back. It is possible to customize this response by
				providing a 'viewName' to be resolved by the Spring MVC
				<code class="interfacename">ViewResolver</code>
				. In the case that the gateway should expect a reply to the
				<code class="interfacename">Message</code>
				then setting the <span class="property">expectReply</span> flag
				(constructor argument) will cause the gateway to wait for a reply
				<code class="interfacename">Message</code>
				before creating an HTTP response. Below is an example of a gateway
				configured to serve as a Spring MVC Controller with a view name.
				Because of the constructor arg value of TRUE, it wait for a reply.
				This also shows how to customize the HTTP methods accepted by the
				gateway, which are <span class="emphasis"><em>POST</em></span> and <span
					class="emphasis"><em>GET</em></span> by default.
			</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"httpInbound"</span>
  <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.integration.http.inbound.HttpRequestHandlingController"</span><span
					class="hl-tag">&gt;</span>
  <span class="hl-tag">&lt;constructor-arg</span> <span
					class="hl-attribute">value</span>=<span class="hl-value">"true"</span><span
					class="hl-tag"> /&gt;</span> <span class="hl-comment">&lt;!-- indicates that a reply is expected --&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"requestChannel"</span> <span class="hl-attribute">ref</span>=<span
					class="hl-value">"httpRequestChannel"</span><span class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"replyChannel"</span> <span class="hl-attribute">ref</span>=<span
					class="hl-value">"httpReplyChannel"</span><span class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"viewName"</span> <span class="hl-attribute">value</span>=<span
					class="hl-value">"jsonView"</span><span class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"supportedMethodNames"</span><span class="hl-tag"> &gt;</span>
    <span class="hl-tag">&lt;list&gt;</span>
      <span class="hl-tag">&lt;value&gt;</span>GET<span class="hl-tag">&lt;/value&gt;</span>
      <span class="hl-tag">&lt;value&gt;</span>DELETE<span
					class="hl-tag">&lt;/value&gt;</span>
    <span class="hl-tag">&lt;/list&gt;</span>
  <span class="hl-tag">&lt;/property&gt;</span>
<span class="hl-tag">&lt;/bean&gt;</span>
			</pre>
			<p>The reply message will be available in the Model map. The key
				that is used for that map entry by default is 'reply', but this can
				be overridden by setting the 'replyKey' property on the endpoint's
				configuration.</p>
		</div>

		<div class="section" title="15.3&nbsp;Http Outbound Gateway">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-outbound"></a>15.3&nbsp;Http Outbound Gateway
						</h2>
					</div>
				</div>
			</div>


			<p>
				To configure the
				<code class="classname">HttpRequestExecutingMessageHandler</code>
				write a bean definition like this:
			</p>

			<pre class="programlisting">
				<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"httpOutbound"</span>
  <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler"</span><span
					class="hl-tag">&gt;</span>
  <span class="hl-tag">&lt;constructor-arg</span> <span
					class="hl-attribute">value</span>=<span class="hl-value">"http://localhost:8080/example"</span><span
					class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"outputChannel"</span> <span class="hl-attribute">ref</span>=<span
					class="hl-value">"responseChannel"</span><span class="hl-tag"> /&gt;</span>
<span class="hl-tag">&lt;/bean&gt;</span>
			</pre>

			<p>
				This bean definition will execute HTTP requests by delegating to a
				<code class="classname">RestTemplate</code>
				. That template in turn delegates to a list of HttpMessageConverters
				to generate the HTTP request body from the Message payload. You can
				configure those converters as well as the ClientHttpRequestFactory
				instance to use:
			</p>

			<pre class="programlisting">
				<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"httpOutbound"</span>
  <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler"</span><span
					class="hl-tag">&gt;</span>
  <span class="hl-tag">&lt;constructor-arg</span> <span
					class="hl-attribute">value</span>=<span class="hl-value">"http://localhost:8080/example"</span><span
					class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"outputChannel"</span> <span class="hl-attribute">ref</span>=<span
					class="hl-value">"responseChannel"</span><span class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"messageConverters"</span> <span
					class="hl-attribute">ref</span>=<span class="hl-value">"messageConverterList"</span><span
					class="hl-tag"> /&gt;</span>
  <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"requestFactory"</span> <span class="hl-attribute">ref</span>=<span
					class="hl-value">"customRequestFactory"</span><span class="hl-tag"> /&gt;</span>
<span class="hl-tag">&lt;/bean&gt;</span>
			</pre>

			<p>
				By default the HTTP request will be generated using an instance of
				<code class="classname">SimpleClientHttpRequestFactory</code>
				which uses the JDK
				<code class="classname">HttpURLConnection</code>
				. Use of the Apache Commons HTTP Client is also supported through
				the provided
				<code class="classname">CommonsClientHttpRequestFactory</code>
				which can be injected as shown above.
			</p>
			<p></p>
			<div class="note" title="Note"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Note">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Note]" src="images/admon/note.png"></td>
						<th align="left">Note</th>
					</tr>
					<tr>
						<td align="left" valign="top">In the case of the Outbound
							Gateway, the reply message produced by the gateway will contain
							all Message Headers present in the request message.</td>
					</tr>
				</table>
			</div>
			<p></p>
			<p>
				<span class="emphasis"><em>Cookies</em></span>
			</p>
			<p>
				Basic cookie support is provided by the <span class="emphasis"><em>transfer-cookies</em></span>
				attribute on the outbound gateway. When set to true (default is
				false), a <span class="emphasis"><em>Set-Cookie</em></span> header
				received from the server in a response will be converted to <span
					class="emphasis"><em>Cookie</em></span> in the reply message. This
				header will then be used on subsequent sends. This enables simple
				stateful interactions, such as...
			</p>
			<p>
				<span class="emphasis"><em>...-&gt;logonGateway-&gt;...-&gt;doWorkGateway-&gt;...-&gt;logoffGateway-&gt;...</em></span>
			</p>
			<p>
				If <span class="emphasis"><em>transfer-cookies</em></span> is false,
				any <span class="emphasis"><em>Set-Cookie</em></span> header
				received will remain as <span class="emphasis"><em>Set-Cookie</em></span>
				in the reply message, and will be dropped on subsequent sends.
			</p>
		</div>

		<div class="section" title="15.4&nbsp;HTTP Namespace Support">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-namespace"></a>15.4&nbsp;HTTP Namespace Support
						</h2>
					</div>
				</div>
			</div>



			<p>
				Spring Integration provides an <span class="emphasis"><em>http</em></span>
				namespace and the corresponding schema definition. To include it in
				your configuration, simply provide the following namespace
				declaration in your application context configuration file:
			</p>

			<pre class="programlisting">
				<span class="hl-directive" style="color: maroon">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="hl-tag">&lt;beans</span> <span class="hl-attribute">xmlns</span>=<span
					class="hl-value">"http://www.springframework.org/schema/beans"</span>
  <span class="hl-attribute">xmlns:xsi</span>=<span class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span>
  <span class="hl-attribute">xmlns:int</span>=<span class="hl-value">"http://www.springframework.org/schema/integration"</span>
  <span class="hl-attribute">xmlns:int-http</span>=<span
					class="hl-value">"http://www.springframework.org/schema/integration/http"</span>
  <span class="hl-attribute">xsi:schemaLocation</span>=<span
					class="hl-value">"
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/integration/http
    http://www.springframework.org/schema/integration/http/spring-integration-http.xsd"</span><span
					class="hl-tag">&gt;</span>
    ...
<span class="hl-tag">&lt;/beans&gt;</span>
			</pre>

			<p>
				<span class="emphasis"><em>Inbound</em></span>
			</p>

			<p>
				The XML Namespace provides two components for handling HTTP Inbound
				requests. In order to process requests without returning a dedicated
				response, use the <span class="emphasis"><em>inbound-channel-adapter</em></span>:
			</p>

			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:inbound-channel-adapter</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"httpChannelAdapter"</span> <span
					class="hl-attribute">channel</span>=<span class="hl-value">"requests"</span>
    <span class="hl-attribute">supported-methods</span>=<span
					class="hl-value">"PUT, DELETE"</span><span class="hl-tag">/&gt;</span>
			</pre>

			<p>
				To process requests that do expect a response, use an <span
					class="emphasis"><em>inbound-gateway</em></span>:
			</p>

			<pre class="programlisting"> <span class="hl-tag">&lt;int-http:inbound-gateway</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"inboundGateway"</span>
    <span class="hl-attribute">request-channel</span>=<span
					class="hl-value">"requests"</span>
    <span class="hl-attribute">reply-channel</span>=<span
					class="hl-value">"responses"</span><span class="hl-tag">/&gt;</span>
			</pre>

			<div class="important" title="Important"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Important">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Important]" src="images/admon/important.png"></td>
						<th align="left">Important</th>
					</tr>
					<tr>
						<td align="left" valign="top">
							<p>
								Beginning with <span class="emphasis"><em>Spring
										Integration 2.1</em></span> the <span class="emphasis"><em>HTTP
										Inbound Gateway</em></span> and the <span class="emphasis"><em>HTTP
										Inbound Channel Adapter</em></span> should use the <span class="emphasis"><em>path</em></span>
								attribute instead of the <span class="emphasis"><em>name</em></span>
								attribute for specifying the request path. The <span
									class="emphasis"><em>name</em></span> attribute for those 2
								components has been deprecated.
							</p>
							<p>
								If you simply want to identify component itself within your
								application context, please use the <span class="emphasis"><em>id</em></span>
								attribute.
							</p>
						</td>
					</tr>
				</table>
			</div>

			<p>
				<span class="emphasis"><em>Defining the
						UriPathHandlerMapping</em></span>
			</p>

			<p>
				In order to use the <span class="emphasis"><em>HTTP
						Inbound Gateway</em></span> or the <span class="emphasis"><em>HTTP
						Inbound Channel Adapter</em></span> you must define a

				<code class="interfacename">
					<a class="ulink"
						href="http://static.springsource.org/spring-integration/api/org/springframework/integration/http/inbound/UriPathHandlerMapping.html"
						target="_top">UriPathHandlerMapping</a>
				</code>
				. This particular implementation of the <a class="ulink"
					href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/web/servlet/HandlerMapping.html"
					target="_top"><code class="interfacename">HandlerMapping</code></a>
				matches against the value of the <span class="emphasis"><em>path</em></span>
				attribute.
			</p>

			<pre class="programlisting">
				<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">class</span>=<span
					class="hl-value">"org.springframework.integration.http.inbound.UriPathHandlerMapping"</span><span
					class="hl-tag">/&gt;</span>
			</pre>
			<p>
				For more information regarding <span class="emphasis"><em>Handler
						Mappings</em></span>, please see:
			</p>

			<div class="itemizedlist">
				<ul class="itemizedlist" type="disc">
					<li class="listitem"><a class="ulink"
						href="http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-handlermapping"
						target="_top">http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-handlermapping</a>
					</li>
				</ul>
			</div>

			<p>
				<span class="emphasis"><em>URI Template Variables and
						Expressions</em></span>
			</p>

			<p>
				By Using the <span class="emphasis"><em>path</em></span> attribute
				in conjunction with the <span class="emphasis"><em>payload-expression</em></span>
				attribute as well as the <span class="emphasis"><em>
						header</em></span> sub-element, you have a high degree of flexiblity for
				mapping inbound request data.
			</p>

			<p>
				In the following example configuration, an Inbound Channel Adapter
				is configured to accept requests using the following URI: <span
					class="emphasis"><em>/first-name/{firstName}/last-name/{lastName}</em></span>
			</p>

			<p>
				Using the <span class="emphasis"><em>payload-expression</em></span>
				attribute, the URI template variable <span class="emphasis"><em>{firstName}</em></span>
				is mapped to be the Message payload, while the <span
					class="emphasis"><em>{lastName}</em></span> URI template variable
				will map to the <span class="emphasis"><em>lname</em></span> Message
				header.
			</p>

			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:inbound-channel-adapter</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"inboundAdapterWithExpressions"</span>
                                  <span class="hl-attribute">path</span>=<span
					class="hl-value">"/first-name/{firstName}/last-name/{lastName}"</span>
                                  <span class="hl-attribute">channel</span>=<span
					class="hl-value">"requests"</span>
                                  <span class="hl-attribute">payload-expression</span>=<span
					class="hl-value">"#pathVariables.firstName"</span><span
					class="hl-tag">&gt;</span>
        <span class="hl-tag">&lt;int-http:header</span> <span
					class="hl-attribute">name</span>=<span class="hl-value">"lname"</span> <span
					class="hl-attribute">expression</span>=<span class="hl-value">"#pathVariables.lastName"</span><span
					class="hl-tag">/&gt;</span>
<span class="hl-tag">&lt;/int-http:inbound-channel-adapter&gt;</span>
			</pre>

			<p>
				For more information about <span class="emphasis"><em>URI
						template variables</em></span>, please see the Spring Reference Manual:
			</p>

			<div class="itemizedlist">
				<ul class="itemizedlist" type="disc">
					<li class="listitem"><a class="ulink"
						href="http://static.springsource.org/spring/docs/current/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-ann-requestmapping"
						target="_top">http://static.springsource.org/spring/docs/current/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-ann-requestmapping</a>
					</li>
				</ul>
			</div>

			<p>
				<span class="emphasis"><em>Outbound</em></span>
			</p>

			<p>
				To configure the outbound gateway you can use the namespace support
				as well. The following code snippet shows the different
				configuration options for an outbound Http gateway. Most
				importantly, notice that the 'http-method' and
				'expected-response-type' are provided. Those are two of the most
				commonly configured values. The default http-method is POST, and the
				default response type is <span class="emphasis"><em>null</em></span>.
				With a null response type, the payload of the reply Message would
				contain the ResponseEntity as long as it's http status is a success
				(non-successful status codes will throw Exceptions). If you are
				expecting a different type, such as a
				<code class="classname">String</code>
				, then provide that fully-qualified class name as shown below.
			</p>
			<div class="important" title="Important"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Important">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Important]" src="images/admon/important.png"></td>
						<th align="left">Important</th>
					</tr>
					<tr>
						<td align="left" valign="top">Beginning with Spring
							Integration 2.1 the <span class="emphasis"><em>request-timeout</em></span>
							attribute of the HTTP Outbound Gateway was renamed to <span
							class="emphasis"><em>reply-timeout</em></span> to better reflect
							the intent.
						</td>
					</tr>
				</table>
			</div>
			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:outbound-gateway</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"example"</span>
    <span class="hl-attribute">request-channel</span>=<span
					class="hl-value">"requests"</span>
    <span class="hl-attribute">url</span>=<span class="hl-value">"http://localhost/test"</span>
    <span class="hl-attribute">http-method</span>=<span class="hl-value">"POST"</span>
    <span class="hl-attribute">extract-request-payload</span>=<span
					class="hl-value">"false"</span>
    <span class="hl-attribute">expected-response-type</span>=<span
					class="hl-value">"java.lang.String"</span>
    <span class="hl-attribute">charset</span>=<span class="hl-value">"UTF-8"</span>
    <span class="hl-attribute">request-factory</span>=<span
					class="hl-value">"requestFactory"</span>
    <span class="hl-attribute">reply-timeout</span>=<span
					class="hl-value">"1234"</span>
    <span class="hl-attribute">reply-channel</span>=<span
					class="hl-value">"replies"</span><span class="hl-tag">/&gt;</span>
			</pre>
			<div class="important" title="Important"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Important">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Important]" src="images/admon/important.png"></td>
						<th align="left">Important</th>
					</tr>
					<tr>
						<td align="left" valign="top">
							<p>
								Since <span class="emphasis"><em>Spring Integration
										2.2</em></span>, Java serialization over HTTP is no longer enabled by
								default. Previously, when setting the
								<code class="code">expected-response-type</code>
								attribute to a
								<code class="code">Serializable</code>
								object, the
								<code class="code">Accept</code>
								header was not properly set up. Since <span class="emphasis"><em>Spring
										Integration 2.2</em></span>, the
								<code class="classname">SerializingHttpMessageConverter</code>
								has now been updated to set the
								<code class="code">Accept</code>
								header to
								<code class="code">application/x-java-serialized-object</code>
								.
							</p>
							<p>
								However, because this could cause incompatibility with existing
								applications, it was decided to no longer automatically add this
								converter to the HTTP endpoints. If you wish to use Java
								serialization, you will need to add the
								<code class="classname">SerializingHttpMessageConverter</code>
								to the appropriate endpoints, using the
								<code class="code">message-converters</code>
								attribute, when using XML configuration, or using the
								<code class="code">setMessageConverters()</code>
								method. Alternatively, you may wish to consider using JSON
								instead which is enabled by simply having
								<code class="code">Jackson</code>
								on the classpath.
							</p>
						</td>
					</tr>
				</table>
			</div>
			<p>
				Beginning with Spring Integration 2.2 you can also determine the
				HTTP Method dynamically using SpEL and the <span class="emphasis"><em>http-method-expression</em></span>
				attribute. Note that this attribute is obviously murually exclusive
				with <span class="emphasis"><em>http-method</em></span> You can also
				use
				<code class="code">expected-response-type-expression</code>
				attribute instead of
				<code class="code">expected-response-type</code>
				and provide any valid SpEL expression that determines the type of
				the response.
			</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:outbound-gateway</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"example"</span>
    <span class="hl-attribute">request-channel</span>=<span
					class="hl-value">"requests"</span>
    <span class="hl-attribute">url</span>=<span class="hl-value">"http://localhost/test"</span>
    <span class="hl-attribute">http-method-expression</span>=<span
					class="hl-value">"headers.httpMethod"</span>
    <span class="hl-attribute">extract-request-payload</span>=<span
					class="hl-value">"false"</span>
    <span class="hl-attribute">expected-response-type-expression</span>=<span
					class="hl-value">"payload"</span>
    <span class="hl-attribute">charset</span>=<span class="hl-value">"UTF-8"</span>
    <span class="hl-attribute">request-factory</span>=<span
					class="hl-value">"requestFactory"</span>
    <span class="hl-attribute">reply-timeout</span>=<span
					class="hl-value">"1234"</span>
    <span class="hl-attribute">reply-channel</span>=<span
					class="hl-value">"replies"</span><span class="hl-tag">/&gt;</span>
			</pre>
			<p></p>
			<p>If your outbound adapter is to be used in a unidirectional
				way, then you can use an outbound-channel-adapter instead. This
				means that a successful response will simply execute without sending
				any Messages to a reply channel. In the case of any non-successful
				response status code, it will throw an exception. The configuration
				looks very similar to the gateway:</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:outbound-channel-adapter</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"example"</span>
      <span class="hl-attribute">url</span>=<span class="hl-value">"http://localhost/example"</span>
      <span class="hl-attribute">http-method</span>=<span
					class="hl-value">"GET"</span>
      <span class="hl-attribute">channel</span>=<span class="hl-value">"requests"</span>
      <span class="hl-attribute">charset</span>=<span class="hl-value">"UTF-8"</span>
      <span class="hl-attribute">extract-payload</span>=<span
					class="hl-value">"false"</span>
      <span class="hl-attribute">expected-response-type</span>=<span
					class="hl-value">"java.lang.String"</span>
      <span class="hl-attribute">request-factory</span>=<span
					class="hl-value">"someRequestFactory"</span>
      <span class="hl-attribute">order</span>=<span class="hl-value">"3"</span>
      <span class="hl-attribute">auto-startup</span>=<span
					class="hl-value">"false"</span><span class="hl-tag">/&gt;</span>
			</pre>
			<p></p>
			<div class="note" title="Note"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Note">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Note]" src="images/admon/note.png"></td>
						<th align="left">Note</th>
					</tr>
					<tr>
						<td align="left" valign="top">
							<p>To specify the URL; you can use either the 'url' attribute
								or the 'url-expression' attribute. The 'url' is a simple string
								(with placedholders for URI variables, as described below); the
								'url-expression' is a SpEL expression, with the Message as the
								root object, enabling dynamic urls. The url resulting from the
								expression evaluation can still have placeholders for URI
								variables.</p>
							<p>In previous releases, some users used the place holders to
								replace the entire URL with a URI variable. Changes in Spring
								3.1 can cause some issues with escaped characters, such as '?'.
								For this reason, it is recommended that if you wish to generate
								the URL entirely at runtime, you use the 'url-expression'
								attribute.</p>
						</td>
					</tr>
				</table>
			</div>
			<p>
				<span class="emphasis"><em>Mapping URI variables</em></span>
			</p>
			<p>
				If your URL contains URI variables, you can map them using the
				<code class="code">uri-variable</code>
				sub-element. This sub-element is available for the <span
					class="emphasis"><em>Http Outbound Gateway</em></span> and the <span
					class="emphasis"><em>Http Outbound Channel Adapter</em></span>.
			</p>

			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:outbound-gateway</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"trafficGateway"</span>
    <span class="hl-attribute">url</span>=<span class="hl-value">"http://local.yahooapis.com/trafficData?appid=YdnDemo&amp;amp;zip={zipCode}"</span>
		              <span class="hl-attribute">request-channel</span>=<span
					class="hl-value">"trafficChannel"</span>
		              <span class="hl-attribute">http-method</span>=<span
					class="hl-value">"GET"</span>
		              <span class="hl-attribute">expected-response-type</span>=<span
					class="hl-value">"java.lang.String"</span><span class="hl-tag">&gt;</span>
		<span class="hl-tag">&lt;int-http:uri-variable</span> <span
					class="hl-attribute">name</span>=<span class="hl-value">"zipCode"</span> <span
					class="hl-attribute">expression</span>=<span class="hl-value">"payload.getZip()"</span><span
					class="hl-tag">/&gt;</span>
<span class="hl-tag">&lt;/int-http:outbound-gateway&gt;</span>
			</pre>
			<p>
				The
				<code class="code">uri-variable</code>
				sub-element defines two attributes:
				<code class="code">name</code>
				and
				<code class="code">expression</code>
				. The
				<code class="code">name</code>
				attribute identifies the name of the URI variable, while the
				<code class="code">expression</code>
				attribute is used to set the actual value. Using the
				<code class="code">expression</code>
				attribute, you can leverage the full power of the Spring Expression
				Language (SpEL) which gives you full dynamic access to the message
				payload and the message headers. For example, in the above
				configuration the
				<code class="code">getZip()</code>
				method will be invoked on the payload object of the Message and the
				result of that method will be used as the value for the URI variable
				named 'zipCode'.
			</p>

		</div>

		<div class="section" title="15.5&nbsp;Timeout Handling">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-timeout"></a>15.5&nbsp;Timeout Handling
						</h2>
					</div>
				</div>
			</div>


			<p>In the context of HTTP components, there are two timing areas
				that have to be considered.</p>
			<p></p>
			<div class="itemizedlist">
				<ul class="itemizedlist" type="disc">
					<li class="listitem">Timeouts when interacting with Spring
						Integration Channels</li>
					<li class="listitem">Timeouts when interacting with a remote
						HTTP server</li>
				</ul>
			</div>
			<p></p>
			<p>First, the components interact with Message Channels, for
				which timeouts can be specified. For example, an HTTP Inbound
				Gateway will forward messages received from connected HTTP Clients
				to a Message Channel (Request Timeout) and consequently the HTTP
				Inbound Gateway will receive a reply Message from the Reply Channel
				(Reply Timeout) that will be used to generate the HTTP Response.
				Please see the figure below for an illustration.</p>
			<div class="mediaobject" align="center">
				<img src="images/http-inbound-gateway.png" align="middle">
				<div class="caption">
					<p>How timeout settings apply to an HTTP Inbound Gateway</p>
				</div>
			</div>
			<p>For outbound endpoints, the second thing to consider is timing
				while interacting with the remote server.</p>
			<div class="mediaobject" align="center">
				<img src="images/http-outbound-gateway.png" align="middle">
				<div class="caption">
					<p>How timeout settings apply to an HTTP Outbound Gateway</p>
				</div>
			</div>
			<p>
				You may want to configure the HTTP related timeout behavior, when
				making active HTTP requests using the <span class="emphasis"><em>HTTP
						Oubound Gateway</em></span> or the <span class="emphasis"><em>HTTP
						Outbound Channel Adapter</em></span>. In those instances, these two components
				use Spring's
				<code class="classname">
					<a class="ulink"
						href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html"
						target="_top">RestTemplate</a>
				</code>
				support to execute HTTP requests.
			</p>
			<p>
				In order to configure timeouts for the <span class="emphasis"><em>HTTP
						Oubound Gateway</em></span> and the <span class="emphasis"><em>HTTP
						Outbound Channel Adapter</em></span>, you can either reference a
				<code class="classname">RestTemplate</code>
				bean directly, using the <span class="emphasis"><em>rest-template</em></span>
				attribute, or you can provide a reference to a <span
					class="emphasis"><em><a class="ulink"
						href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/http/client/ClientHttpRequestFactory.html"
						target="_top">ClientHttpRequestFactory</a></em></span> bean using the <span
					class="emphasis"><em>request-factory</em></span> attribute. Spring
				provides the following implementations of the
				<code class="interfacename">ClientHttpRequestFactory</code>
				interface:
			</p>

			<p>
				<code class="classname">
					<a class="ulink"
						href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/http/client/SimpleClientHttpRequestFactory.html"
						target="_top">SimpleClientHttpRequestFactory</a>
				</code>
				- Uses standard J2SE facilities for making HTTP Requests
			</p>
			<p>
				<code class="classname">
					<a class="ulink"
						href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.html"
						target="_top">HttpComponentsClientHttpRequestFactory</a>
				</code>
				- Uses <a class="ulink"
					href="http://hc.apache.org/httpcomponents-client-ga/httpclient/"
					target="_top">Apache HttpComponents HttpClient</a> (Since Spring
				3.1)
			</p>
			<p>
				<code class="classname">
					<a class="ulink"
						href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/http/client/CommonsClientHttpRequestFactory.html"
						target="_top">ClientHttpRequestFactory</a>
				</code>
				- Uses <a class="ulink" href="http://hc.apache.org/httpclient-3.x/"
					target="_top">Jakarta Commons HttpClient</a> (Deprecated as of
				Spring 3.1)
			</p>

			<p>
				If you don't explicitly configure the <span class="emphasis"><em>request-factory</em></span>
				or <span class="emphasis"><em>rest-template</em></span> attribute
				respectively, then a default RestTemplate which uses a
				<code class="classname">SimpleClientHttpRequestFactory</code>
				will be instantiated.
			</p>

			<div class="note" title="Note"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Note">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Note]" src="images/admon/note.png"></td>
						<th align="left">Note</th>
					</tr>
					<tr>
						<td align="left" valign="top">
							<p>
								With some JVM implementations, the handling of timeouts using
								the <span class="emphasis"><em>URLConnection</em></span> class
								may not be consistent.
							</p>
							<p>
								E.g. from the <span class="emphasis"><em>Java&#8482;
										Platform, Standard Edition 6 API Specification</em></span> on <span
									class="emphasis"><em>setConnectTimeout</em></span>: <span
									class="quote">&#8220;<span class="quote">Some
										non-standard implmentation of this method may ignore the
										specified timeout. To see the connect timeout set, please call
										getConnectTimeout().</span>&#8221;
								</span>
							</p>
							<p>
								Please test your timeouts if you have specific needs. Consider
								using the
								<code class="classname">HttpComponentsClientHttpRequestFactory</code>
								which, in turn, uses <span class="emphasis"><em><a
										class="ulink"
										href="http://hc.apache.org/httpcomponents-client-ga/"
										target="_top">Apache HttpComponents HttpClient</a></em></span> instead.
							</p>
						</td>
					</tr>
				</table>
			</div>

			<p>
				Here is an example of how to configure an <span class="emphasis"><em>HTTP
						Outbound Gateway</em></span> using a
				<code class="classname">SimpleClientHttpRequestFactory</code>
				, configured with connect and read timeouts of 5 seconds
				respectively:
			</p>

			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:outbound-gateway</span> <span
					class="hl-attribute">url</span>=<span class="hl-value">"http://www.google.com/ig/api?weather={city}"</span>
                           <span class="hl-attribute">http-method</span>=<span
					class="hl-value">"GET"</span>
                           <span class="hl-attribute">expected-response-type</span>=<span
					class="hl-value">"java.lang.String"</span>
                           <span class="hl-attribute">request-factory</span>=<span
					class="hl-value">"requestFactory"</span>
                           <span class="hl-attribute">request-channel</span>=<span
					class="hl-value">"requestChannel"</span>
                           <span class="hl-attribute">reply-channel</span>=<span
					class="hl-value">"replyChannel"</span><span class="hl-tag">&gt;</span>
    <span class="hl-tag">&lt;int-http:uri-variable</span> <span
					class="hl-attribute">name</span>=<span class="hl-value">"city"</span> <span
					class="hl-attribute">expression</span>=<span class="hl-value">"payload"</span><span
					class="hl-tag">/&gt;</span>
<span class="hl-tag">&lt;/int-http:outbound-gateway&gt;</span>

<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"requestFactory"</span>
      <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.http.client.SimpleClientHttpRequestFactory"</span><span
					class="hl-tag">&gt;</span>
    <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"connectTimeout"</span> <span class="hl-attribute">value</span>=<span
					class="hl-value">"5000"</span><span class="hl-tag">/&gt;</span>
    <span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"readTimeout"</span>    <span class="hl-attribute">value</span>=<span
					class="hl-value">"5000"</span><span class="hl-tag">/&gt;</span>
<span class="hl-tag">&lt;/bean&gt;</span>
			</pre>

			<p>
				<span class="emphasis"><em>HTTP Outbound Gateway</em></span>
			</p>
			<p>
				For the <span class="emphasis"><em>HTTP Outbound Gateway</em></span>,
				the XML Schema defines only the <span class="emphasis"><em>reply-timeout</em></span>.
				The <span class="emphasis"><em>reply-timeout</em></span> maps to the
				<span class="emphasis"><em>sendTimeout</em></span> property of the <span
					class="emphasis"><em>org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler</em></span>
				class. More precisely, the property is set on the extended
				<code class="classname">AbstractReplyProducingMessageHandler</code>
				class, which ultimatelly sets the property on the <span
					class="emphasis"><em>MessagingTemplate</em></span>.
			</p>
			<p>
				The value of the <span class="emphasis"><em>sendTimeout</em></span>
				property defaults to "-1" and will be applied to the connected
				<code class="interfacename">MessageChannel</code>
				. This means, that depending on the implementation, the Message
				Channel's <span class="emphasis"><em>send</em></span> method may
				block indefinitely. Furthermore, the <span class="emphasis"><em>sendTimeout</em></span>
				property is only used, when the actual MessageChannel implementation
				has a blocking send (such as 'full' bounded QueueChannel).
			</p>

			<p>
				<span class="emphasis"><em>HTTP Inbound Gateway</em></span>
			</p>
			<p>
				For the <span class="emphasis"><em>HTTP Inbound Gateway</em></span>,
				the XML Schema defines the <span class="emphasis"><em>request-timeout</em></span>
				attribute, which will be used to set the <span class="emphasis"><em>requestTimeout</em></span>
				property on the
				<code class="classname">HttpRequestHandlingMessagingGateway</code>
				class (on the extended MessagingGatewaySupport class). Secondly, the
				<span class="emphasis"><em>reply-timeout</em></span> attribute
				exists and it maps to the <span class="emphasis"><em>replyTimeout</em></span>
				property on the same class.
			</p>
			<p>
				The default for both timeout properties is "1000ms". Ultimately, the
				<span class="emphasis"><em>request-timeout</em></span> property will
				be used to set the <span class="emphasis"><em>sendTimeout</em></span>
				on the used
				<code class="classname">MessagingTemplate</code>
				instance. The <span class="emphasis"><em>replyTimeout</em></span>
				property on the other hand, will be used to set the <span
					class="emphasis"><em>receiveTimeout</em></span> property on the
				used
				<code class="classname">MessagingTemplate</code>
				instance.
			</p>
			<div class="tip" title="Tip"
				style="margin-left: 0.5in; margin-right: 0.5in;">
				<table border="0" summary="Tip">
					<tr>
						<td rowspan="2" align="center" valign="top" width="25"><img
							alt="[Tip]" src="images/admon/tip.png"></td>
						<th align="left">Tip</th>
					</tr>
					<tr>
						<td align="left" valign="top">In order to simulate connection
							timeouts, connect to a non-routable IP address, for example
							10.255.255.10.</td>
					</tr>
				</table>
			</div>
		</div>

		<div class="section" title="15.6&nbsp;HTTP Proxy configuration">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-proxy"></a>15.6&nbsp;HTTP Proxy configuration
						</h2>
					</div>
				</div>
			</div>


			<p>If you are behind a proxy and need to configure proxy settings
				for HTTP outbound adapters and/or gateways, you can apply one of two
				approaches. In most cases, you can rely on the standard Java System
				Properties that control the proxy settings. Otherwise, you can
				explicitly configure a Spring bean for the HTTP client request
				factory instance.</p>

			<p>
				<span class="emphasis"><em>Standard Java Proxy
						configuration</em></span>
			</p>

			<p>There are 3 System Properties you can set to configure the
				proxy settings that will be used by the HTTP protocol handler:</p>
			<div class="itemizedlist">
				<ul class="itemizedlist" type="disc">
					<li class="listitem">
						<p>
							<span class="emphasis"><em>http.proxyHost</em></span> - the host
							name of the proxy server.
						</p>
					</li>
					<li class="listitem">
						<p>
							<span class="emphasis"><em>http.proxyPort</em></span> - the port
							number, the default value being 80.
						</p>
					</li>
					<li class="listitem">
						<p>
							<span class="emphasis"><em>http.nonProxyHosts</em></span> - a
							list of hosts that should be reached directly, bypassing the
							proxy. This is a list of patterns separated by '|'. The patterns
							may start or end with a '*' for wildcards. Any host matching one
							of these patterns will be reached through a direct connection
							instead of through a proxy.
						</p>
					</li>
				</ul>
			</div>
			<p>And for HTTPS:</p>
			<div class="itemizedlist">
				<ul class="itemizedlist" type="disc">
					<li class="listitem">
						<p>
							<span class="emphasis"><em>https.proxyHost</em></span> - the host
							name of the proxy server.
						</p>
					</li>
					<li class="listitem">
						<p>
							<span class="emphasis"><em>https.proxyPort</em></span> - the port
							number, the default value being 80.
						</p>
					</li>
				</ul>
			</div>
			<p>For more information please refer to this document:
				http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
			</p>

			<p>
				<span class="emphasis"><em>Spring's
						SimpleClientHttpRequestFactory</em></span>
			</p>
			<p>
				If for any reason, you need more explicit control over the proxy
				configuration, you can use Spring's
				<code class="classname">SimpleClientHttpRequestFactory</code>
				and configure its 'proxy' property as such:
			</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"requestFactory"</span>
    			<span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.http.client.SimpleClientHttpRequestFactory"</span><span
					class="hl-tag">&gt;</span>
	<span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"proxy"</span><span class="hl-tag">&gt;</span>
		<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"proxy"</span> <span class="hl-attribute">class</span>=<span
					class="hl-value">"java.net.Proxy"</span><span class="hl-tag">&gt;</span>
			<span class="hl-tag">&lt;constructor-arg&gt;</span>
				<span class="hl-tag">&lt;util:constant</span> <span
					class="hl-attribute">static-field</span>=<span class="hl-value">"java.net.Proxy.Type.HTTP"</span><span
					class="hl-tag">/&gt;</span>
			<span class="hl-tag">&lt;/constructor-arg&gt;</span>
			<span class="hl-tag">&lt;constructor-arg&gt;</span>
				<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">class</span>=<span
					class="hl-value">"java.net.InetSocketAddress"</span><span
					class="hl-tag">&gt;</span>
					<span class="hl-tag">&lt;constructor-arg</span> <span
					class="hl-attribute">value</span>=<span class="hl-value">"123.0.0.1"</span><span
					class="hl-tag">/&gt;</span>
					<span class="hl-tag">&lt;constructor-arg</span> <span
					class="hl-attribute">value</span>=<span class="hl-value">"8080"</span><span
					class="hl-tag">/&gt;</span>
				<span class="hl-tag">&lt;/bean&gt;</span>
			<span class="hl-tag">&lt;/constructor-arg&gt;</span>
		<span class="hl-tag">&lt;/bean&gt;</span>
	<span class="hl-tag">&lt;/property&gt;</span>
<span class="hl-tag">&lt;/bean&gt;</span>
			</pre>
			<p></p>

		</div>

		<div class="section" title="15.7&nbsp; HTTP Header Mappings">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-header-mapping"></a>15.7&nbsp; HTTP Header Mappings
						</h2>
					</div>
				</div>
			</div>

			<p>Spring Integration provides support for Http Header mapping
				for both HTTP Request and HTTP Responses.</p>

			<p>By default all standard Http Headers as defined here
				http://en.wikipedia.org/wiki/List_of_HTTP_header_fields will be
				mapped from the message to HTTP request/response headers without
				further configuration. However if you do need further customization
				you may provide additional configuration via convenient namespace
				support. You can provide a comma-separated list of header names, and
				you can also include simple patterns with the '*' character acting
				as a wildcard. If you do provide such values, it will override the
				default behavior. Basically, it assumes you are in complete control
				at that point. However, if you do want to include all of the
				standard HTTP headers, you can use the shortcut patterns:
				HTTP_REQUEST_HEADERS and HTTP_RESPONSE_HEADERS. Here are some
				examples:</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:outbound-gateway</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"httpGateway"</span>
			<span class="hl-attribute">url</span>=<span class="hl-value">"http://localhost/test2"</span>
			<span class="hl-attribute">mapped-request-headers</span>=<span
					class="hl-value">"foo, bar"</span>
			<span class="hl-attribute">mapped-response-headers</span>=<span
					class="hl-value">"X-*, HTTP_RESPONSE_HEADERS"</span>
			<span class="hl-attribute">channel</span>=<span class="hl-value">"someChannel"</span><span
					class="hl-tag">/&gt;</span>

<span class="hl-tag">&lt;int-http:outbound-channel-adapter</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"httpAdapter"</span>
			<span class="hl-attribute">url</span>=<span class="hl-value">"http://localhost/test2"</span>
			<span class="hl-attribute">mapped-request-headers</span>=<span
					class="hl-value">"foo, bar, HTTP_REQUEST_HEADERS"</span>
			<span class="hl-attribute">channel</span>=<span class="hl-value">"someChannel"</span><span
					class="hl-tag">/&gt;</span>
			</pre>
			<p>

				The adapters and gateways will use the
				<code class="classname">DefaultHttpHeaderMapper</code>
				which now provides two static factory methods for "inbound" and
				"outbound" adapters so that the proper direction can be applied
				(mapping HTTP requests/responses IN/OUT as appropriate).
			</p>
			<p>
				If further customization is required you can also configure a
				<code class="classname">DefaultHttpHeaderMapper</code>
				independently and inject it into the adapter via the
				<code class="code">header-mapper</code>
				attribute.

			</p>
			<pre class="programlisting">
				<span class="hl-tag">&lt;int-http:outbound-gateway</span> <span
					class="hl-attribute">id</span>=<span class="hl-value">"httpGateway"</span>
			<span class="hl-attribute">url</span>=<span class="hl-value">"http://localhost/test2"</span>
			<span class="hl-attribute">header-mapper</span>=<span
					class="hl-value">"headerMapper"</span>
			<span class="hl-attribute">channel</span>=<span class="hl-value">"someChannel"</span><span
					class="hl-tag">/&gt;</span>

<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
					class="hl-value">"headerMapper"</span> <span class="hl-attribute">class</span>=<span
					class="hl-value">"org.springframework.integration.http.support.DefaultHttpHeaderMapper"</span><span
					class="hl-tag">&gt;</span>
		<span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"inboundHeaderNames"</span> <span
					class="hl-attribute">value</span>=<span class="hl-value">"foo*, *bar, baz"</span><span
					class="hl-tag">/&gt;</span>
		<span class="hl-tag">&lt;property</span> <span class="hl-attribute">name</span>=<span
					class="hl-value">"outboundHeaderNames"</span> <span
					class="hl-attribute">value</span>=<span class="hl-value">"a*b, d"</span><span
					class="hl-tag">/&gt;</span>
<span class="hl-tag">&lt;/bean&gt;</span>
			</pre>
			<p></p>
			<p>
				Of course, you can even implement the HeaderMapper strategy
				interface directly and provide a reference to that if you need to do
				something other than what the
				<code class="classname">DefaultHttpHeaderMapper</code>
				supports.
			</p>
		</div>

		<div class="section" title="15.8&nbsp;HTTP Samples">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title" style="clear: both">
							<a name="http-samples"></a>15.8&nbsp;HTTP Samples
						</h2>
					</div>
				</div>
			</div>

			<div class="section"
				title="15.8.1&nbsp;Multipart HTTP request - RestTemplate (client) and Http Inbound Gateway (server)">
				<div class="titlepage">
					<div>
						<div>
							<h3 class="title">
								<a name="multipart-rest-inbound"></a>15.8.1&nbsp;Multipart HTTP
								request - RestTemplate (client) and Http Inbound Gateway
								(server)
							</h3>
						</div>
					</div>
				</div>

				<p>
					This example demonstrates how simple it is to send a Multipart HTTP
					request via Spring's RestTemplate and receive it with a Spring
					Integration HTTP Inbound Adapter. All we are doing is creating a
					<code class="classname">MultiValueMap</code>
					and populating it with multi-part data. The
					<code class="classname">RestTemplate</code>
					will take care of the rest (no pun intended) by converting it
					to&nbsp;a
					<code class="classname">MultipartHttpServletRequest</code>
					.&nbsp;This particular client will send a multipart HTTP Request
					which contains the name of the company as well as an image file
					with the company logo.
				</p>
				<pre class="programlisting">RestTemplate template =&nbsp;<span
						class="hl-keyword">new</span>&nbsp;RestTemplate();
String uri =&nbsp;<span class="hl-string">"http://localhost:8080/multipart-http/inboundAdapter.htm"</span>;
Resource s2logo =&nbsp;
   <span class="hl-keyword">new</span>&nbsp;ClassPathResource(<span
						class="hl-string">"org/springframework/samples/multipart/spring09_logo.png"</span>);
MultiValueMap map =&nbsp;<span class="hl-keyword">new</span>&nbsp;LinkedMultiValueMap();
map.add(<span class="hl-string">"company"</span>,&nbsp;<span
						class="hl-string">"SpringSource"</span>);
map.add(<span class="hl-string">"company-logo"</span>, s2logo);
HttpHeaders headers =&nbsp;<span class="hl-keyword">new</span>&nbsp;HttpHeaders();
headers.setContentType(<span class="hl-keyword">new</span>&nbsp;MediaType(<span
						class="hl-string">"multipart"</span>,&nbsp;<span class="hl-string">"form-data"</span>));
HttpEntity request =&nbsp;<span class="hl-keyword">new</span>&nbsp;HttpEntity(map, headers);
ResponseEntity&lt;?&gt; httpResponse = template.exchange(uri, HttpMethod.POST, request,&nbsp;null);</pre>
				<p></p>
				<p>That is all for the client.</p>
				<p>On the server side we have the following configuration:</p>
				<pre class="programlisting">
					<span class="hl-tag">&lt;int-http:inbound-channel-adapter</span> <span
						class="hl-attribute">id</span>=<span class="hl-value">"httpInboundAdapter"</span>
  <span class="hl-attribute">channel</span>=<span class="hl-value">"receiveChannel"</span>
  <span class="hl-attribute">name</span>=<span class="hl-value">"/inboundAdapter.htm"</span>
  <span class="hl-attribute">supported-methods</span>=<span
						class="hl-value">"GET, POST"</span><span class="hl-tag"> /&gt;</span>

<span class="hl-tag">&lt;int:channel</span> <span class="hl-attribute">id</span>=<span
						class="hl-value">"receiveChannel"</span><span class="hl-tag">/&gt;</span>

<span class="hl-tag">&lt;int:service-activator</span> <span
						class="hl-attribute">input-channel</span>=<span class="hl-value">"receiveChannel"</span><span
						class="hl-tag">&gt;</span>
  <span class="hl-tag">&lt;bean</span> <span class="hl-attribute">class</span>=<span
						class="hl-value">"org.springframework.integration.samples.multipart.MultipartReceiver"</span><span
						class="hl-tag">/&gt;</span>
<span class="hl-tag">&lt;/int:service-activator&gt;</span>

<span class="hl-tag">&lt;bean</span> <span class="hl-attribute">id</span>=<span
						class="hl-value">"multipartResolver"</span>
    <span class="hl-attribute">class</span>=<span class="hl-value">"org.springframework.web.multipart.commons.CommonsMultipartResolver"</span><span
						class="hl-tag">/&gt;</span>
</pre>
				<p></p>
				<p>
					The 'httpInboundAdapter' will receive the request, convert it to a
					<code class="classname">Message</code>
					with a payload that is a&nbsp;
					<code class="classname">LinkedMultiValueMap</code>
					. We then are parsing that in the 'multipartReceiver'
					service-activator;
				</p>
				<pre class="programlisting">
					<span class="hl-keyword">public</span> <span class="hl-keyword">void</span> receive(LinkedMultiValueMap&lt;String, Object&gt; multipartRequest){
  System.out.println(<span class="hl-string">"### Successfully received multipart request ###"</span>);
  <span class="hl-keyword">for</span> (String elementName : multipartRequest.keySet()) {
    <span class="hl-keyword">if</span> (elementName.equals(<span
						class="hl-string">"company"</span>)){
      System.out.println(<span class="hl-string">"\t"</span> + elementName + <span
						class="hl-string">" - "</span> +
        ((String[]) multipartRequest.getFirst(<span class="hl-string">"company"</span>))[<span
						class="hl-number">0</span>]);
    }
    <span class="hl-keyword">else</span> <span class="hl-keyword">if</span> (elementName.equals(<span
						class="hl-string">"company-logo"</span>)){
      System.out.println(<span class="hl-string">"\t"</span> + elementName + <span
						class="hl-string">" - as UploadedMultipartFile: "</span> +
        ((UploadedMultipartFile) multipartRequest.getFirst(<span
						class="hl-string">"company-logo"</span>)).
        											getOriginalFilename());
    }
  }
}

</pre>
				<p>You should see the following output:</p>
				<pre class="programlisting">### Successfully received multipart request ###
   company - SpringSource
   company-logo - as UploadedMultipartFile: spring09_logo.png</pre>
				<p></p>
			</div>
		</div>
	</div>
	<div class="navfooter">
		<hr>
		<table width="100%" summary="Navigation footer">
			<tr>
				<td width="40%" align="left"><a accesskey="p"
					href="gemfire.html">Prev</a>&nbsp;</td>
				<td width="20%" align="center"><a accesskey="u"
					href="spring-integration-adapters.html">Up</a></td>
				<td width="40%" align="right">&nbsp;<a accesskey="n"
					href="ip.html">Next</a></td>
			</tr>
			<tr>
				<td width="40%" align="left" valign="top">14.&nbsp;GemFire
					Support&nbsp;</td>
				<td width="20%" align="center"><a accesskey="h"
					href="index.html">Home</a></td>
				<td width="40%" align="right" valign="top">&nbsp;16.&nbsp;TCP
					and UDP Support</td>
			</tr>
		</table>
	</div>
	<!-- Begin 2nd Google code - a mod -->
	<script type="text/javascript">
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
				: "http://www.");
		document
				.write(unescape("%3Cscript src='"
						+ gaJsHost
						+ "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	</script>
	<script type="text/javascript">
		var OrgTracker = _gat._getTracker("UA-2728886-2");
		OrgTracker._setDomainName("none");
		OrgTracker._setAllowLinker(true);
		OrgTracker._trackPageview();
	</script>
	<!-- End 2nd Google code -->


	<script type="text/javascript">
		function detectLastFrame() {
			var thisF = this.window;
			var allF = parent.top.frames;
			return allF[allF.length - 1] == thisF;
		}

		// Only inject the following code if this is a normal page or the last // frame of a frameset.
		if (parent.top.frames.length == 0 || detectLastFrame()) {
			// Inject the SpringSource search widget too.
			document
					.write(unescape("%3Cscript src='http://search.springsource.org/widget/searchtool.js' type='text/javascript'%3E%3C/script%3E"));
			// Inject the Eloqua code
			document
					.write(unescape("%3Cscript src='/elqNow/elqCfg.js' type='text/javascript'%3E%3C/script%3E"));
			document
					.write(unescape("%3Cscript src='/elqNow/elqImg.js' type='text/javascript'%3E%3C/script%3E"));

		}
	</script>
</body>
</html>